package com.dylan.历史.领扣;

/**
 * @Auther: ankang
 * @Date: 2019/2/23 01:01
 * @Description:
 */
public class $0061旋转链表 {

    class Solution {
        public ListNode rotateRight(ListNode head, int k) {
            if (head == null) {
                return head;
            }
            int n = 1;
            ListNode tail = head;
            for (; tail.next != null; tail = tail.next) {
                n++;
            }
            k = k % n;
            ListNode node = head;
            for (int i = 0; i < n - k; i++) {
                tail.next = node;
                node = node.next;
                tail = tail.next;
                tail.next = null;
            }
            return node;
        }
    }

    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
}
